package com.frxuexi.lib_base.room

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

@Dao
interface AskDao {

    //提交请假
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(askLeave: AskLeave):Long

    /**
     * 审批
     */
    @Update
    fun update(askLeave: AskLeave):Int

    @Delete
    fun delete(askLeave: AskLeave)


    /**
     * 员工查看所有自己的请假记录
     * page:当前第几页
     * size:每页的数据量
     */
    @Query("select * from ask where uid = :uid order by start desc limit (:page-1)*:size,:page*:size")
    fun queryAll(uid:Int,page:Int,size:Int):List<AskLeave>?

    @Query("select count(*) from ask where uid = :uid")
    fun getAskCount(uid:Int):Int


    /**
     * 查看所有未审核的请假列表
     */
    @Query("select * from ask where status='已提交' order by time")
    fun queryNoApprove():List<AskLeave>?
}